package drh.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.ScalarHandler;

import drh.bean.Integral;
import drh.dao.BaseDao;
import drh.dao.IntegralDao;
import handler.IntegralResultSetHandler;

public class IntegralDaoImpl extends BaseDao implements IntegralDao {

	@Override
	public Integer deleteIntegralById(Integer id) {
	try {
		return query.update("dele from Integral where id=?",id);
	} catch (SQLException e) {
		e.printStackTrace();
	}
		return -1;
	}

	@Override
	public Integer updateIntegral(Integral info) {
		try {
			return query.update("update integral set userid=?,orderUID=?,integral=?,time=?,isdelete=?",
					info.getUserid(),info.getOrderUID(),info.getIntegral(),info.getTime(),info.getIsdelete());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return-1;
	}

	@Override
	public Integer addIntegral(Integral info) {
		try {
			return query.update("insert into integral(userid,orderUID,integral,time,isdelete) values(?,?,?,?,?)");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public List<Integral> GetIntegralPaging(Integer pageIndex, Integer pageSize) {
		try {
			return query.query("select * from integral limit ?,?", new IntegralResultSetHandler(),(pageIndex-1)*pageSize,pageSize);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer getCount() {
		String sql = "select count(1) from orders";
		Object query2;
		try {
			 query2 = query.query(sql, new ScalarHandler());
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
	
			e.printStackTrace();
		}
		
		return null;
	}

}
